<template>
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form
        size="small"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="会员信息">
          <el-input
            clearable
            v-model="formInline.nickName"
            placeholder="请输入用户昵称"
          ></el-input>
        </el-form-item>
        <el-form-item label="签到时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker
              size="small"
              v-model="formInline.createTime"
              type="daterange"
              value-format="YYYY-MM-DD"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </div>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search" @click="onSubmit"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <div class="product-content">
      <el-form ref="form" :model="form" label-width="100px">
        <div class="table-wrap">
          <el-table
            size="small"
            :data="tableData"
            border
            style="width: 100%"
            v-loading="loading"
          >
            <el-table-column prop="userId" label="ID"></el-table-column>
            <el-table-column prop="nickName" label="会员信息"></el-table-column>
            <el-table-column
              prop="minDate"
              label="首次签到时间"
            ></el-table-column>
            <el-table-column
              prop="lastDate"
              label="上次签到时间"
            ></el-table-column>
            <el-table-column
              prop="maxDate"
              label="最后一次签到时间"
            ></el-table-column>
            <el-table-column
              prop="totalDay"
              label="累计签到天数"
            ></el-table-column>
            <el-table-column
              prop="continuousDays"
              label="最长签到天数"
            ></el-table-column>
            <el-table-column prop="prize" label="签到奖励">
              <template #default="scope">
                <div>
                  {{ scope.row.points }}积分;
                  <div v-for="(item, index) in scope.row.coupon" :key="index">
                    <text class="orange">{{ item.name }}</text> x{{
                      item.couponNum
                    }};
                  </div>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import SignApi from "@/api/sign.js";
import { formatDate } from "@/utils/DateTime.js";
export default {
  data() {
    return {
      formInline: {
        nickName: "",
        createTime: [],
      },
      form: {},
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*是否加载完成*/
      loading: true,
      /*搜索条件*/
      daysList: [
        "2天",
        "3天",
        "4天",
        "5天",
        "6天",
        "7天",
        "15天",
        "30天",
        "60天",
      ],
      /*搜索条件*/
      signTime: ["最近7天", "最近15天", "最近30天", "自定义"],
    };
  },
  created() {
    /*获取列表*/
    this.getData();
  },
  methods: {
    /*获取列表*/
    getData() {
      let self = this;
      let Params = {};
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      SignApi.getSignList(Params, true)
        .then((res) => {
          self.loading = false;
          self.tableData = res.data.records;
          self.totalDataNumber = res.data.total;
        })
        .catch((error) => {});
    },
    onSubmit() {
      let self = this;
      let Params = {};
      Params.startDate = self.formInline.createTime[0];
      Params.endDate = self.formInline.createTime[1];
      Params.nickName = self.formInline.nickName;
      Params.pageIndex = self.curPage;
      Params.pageSize = self.pageSize;
      self.loading = true;
      SignApi.getSignList(Params, true)
        .then((data) => {
          self.loading = false;
          self.tableData = data.data.records;
          self.totalDataNumber = data.data.total;
        })
        .catch((error) => {});
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getData();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getData();
    },
  },
};
</script>

<style></style>
